package com.xnck.example.jertest.controller;

import com.xnck.example.jertest.annotation.AuthenPassport;
import com.xnck.example.jertest.entity.DicInfo;
import com.xnck.example.jertest.service.TestService;
import com.xnck.example.jertest.util.ResponseUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("test")
public class TestController {

    public final static Logger log = Logger.getLogger(TestController.class);

    @Autowired
    private TestService testService;

    @ResponseBody
    @RequestMapping(value = "default", method = RequestMethod.GET)
    public void getDefault() {
        try {
            ResponseUtil.responseSuccessMsg(null, "我是默认的测试信息");
        } catch (Exception e) {
            log.error(e);
        }
    }

    @AuthenPassport
    @ResponseBody
    @RequestMapping(value = "right", method = RequestMethod.GET)
    public void getRight() {
        try {
            ResponseUtil.responseSuccessMsg(null, "看到我，就代表通过了拦截");
        } catch (Exception e) {
            log.error(e);
        }
    }

    @RequestMapping(value = "forwarddft", method = RequestMethod.GET)
    public String forwardDefault() {
        return "forward:default.page";
    }

    @RequestMapping(value = "craetedic", method = RequestMethod.GET)
    public void getCreateDic(@RequestParam(value = "name")String name) {
        try {
            DicInfo dicInfo = testService.createDic(name);
            ResponseUtil.responseSuccessMsg(dicInfo, "新的DicInfo");
        } catch (Exception e) {
            log.error(e);
            ResponseUtil.responseErrorMsg("内部异常");
        }
    }
}
